﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SimpleChat
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            string jsonIpconfig = File.ReadAllText("Config.json");
            IPConfig ipconfig = JsonSerializer.Deserialize<IPConfig>(jsonIpconfig);
            textBox1.Text = ipconfig.ServerIPv4;
            textBox2.Text = ipconfig.ServerPort.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var ipconfig = new IPConfig();
            ipconfig.ServerIPv4 = textBox1.Text;
            ipconfig.ServerPort = int.Parse(textBox2.Text);
            string jsonIpconfig = JsonSerializer.Serialize(ipconfig);
            File.WriteAllText("Config.json", jsonIpconfig);
            
            Task.Run(() =>
            { 
                MessageManager.Instance.UpdateMessageManagerConfig();
            });
            this.Close();
        }

    }
}
